package net.kangyee.eventmanager.commands;

import org.bukkit.entity.Player;

import net.kangyee.eventmanager.EventManager;
import net.kangyee.eventmanager.util.ConfigManager;
import net.kangyee.eventmanager.util.MessageManager;

public class CmdJoin extends EventManagerCommand{
	
	private ConfigManager config;
	private EventManager plugin;
	
	public CmdJoin(EventManager plugin, ConfigManager config){
		this.plugin = plugin;
		this.config = config;
	}

	public void onCommand(Player player, String[] args){
    	if (!plugin.getEventRegState() && !player.hasPermission("eventmanager.admin.toggle")){
    		MessageManager.sendNormalMessage(player, "&c目前服务器暂不允许报名参加活动");
    		return;
    	}
    	if (!config.configAdminCheckOnJoin && (player.hasPermission("eventmanager.admin") || player.isOp())){
    		MessageManager.sendNormalMessage(player, "&c无法以管理员身份加入活动");
    		return;
    	}
    	if(plugin.regPlayers.containsKey(player)){
    		MessageManager.sendNormalMessage(player, "&c你已经报名参加过了,请不要重复报名参加");
    		return;
    	}
    	plugin.regPlayers.put(player.getPlayer(), false);
    	MessageManager.sendNormalMessageToAll(config.messageJoin.replaceAll("%name%", player.getDisplayName())
				.replaceAll("%event%", plugin.getEventName())
				.replaceAll("%count%", String.valueOf(plugin.getRegCount())));
    	MessageManager.sendNormalMessage(player, "你成功报名参加活动:&c" + plugin.getEventName() + "&f,输入&6/em quit&f可退出活动");
		return;
	}

	public String getCmdName(){
		return "join";
	}

	public String getArgs(){
		return "";
	}
	
	public int getMaxArgs(){
		return 1;
	}

	public int getMinArgs(){
		return 1;
	}

	public String getPermission(){
		return "eventmanager.player." + getCmdName();
	}

	public boolean getStateRequire(){
		return true;
	}
	
	public boolean getRegPCRequire() {
		return false;
	}
}
